﻿@using Microsoft.AspNetCore.Localization
@using SimplCommerce.Infrastructure
@using SimplCommerce.Module.Core.Extensions

@inject IViewLocalizer Localizer
@inject IWorkContext WorkContext

@{
    var uiCulture = Context.Features.Get<IRequestCultureFeature>().RequestCulture.UICulture.Name;
    var selectedCulture = (await WorkContext.GetCurrentUser()).Culture;
}

@if (GlobalConfiguration.Cultures.Count() > 1)
{
<li class="nav-item dropdown">
    <a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown">
        Language (@uiCulture)
        <span class="caret"></span>
    </a>
    <ul class="dropdown-menu lang-selector">
        @foreach (var culture in GlobalConfiguration.Cultures)
        {
            <li class="dropdown-item">
                <a href="#" data-value="@culture.Id">@culture.Name
                @if (culture.Id == selectedCulture)
                {
                    <span class="glyphicon glyphicon-ok" aria-hidden="true"></span>
                }
                </a>
            </li>
        }
    </ul>
    <form asp-area="Localization" asp-controller="Localization" asp-action="SetLanguage" asp-route-returnUrl="@Context.Request.Path" method="post" id="lang-form" role="form">
        <input type="hidden" name="culture" value="@uiCulture" />
    </form>
</li>
}
